import { createVNode, render } from 'vue'
import component from "./Tip.vue"

function tip(str:any, type:any, withIcon = false) {
    const div = document.createElement('div')
    document.body.appendChild(div)
    const vNode = createVNode(component, { type, str, withIcon })
    render(vNode, div)

    const timer = setTimeout(() => {
        render(null, div)
        clearTimeout(timer)
    }, 3500)
}

export default {
    warn: (str:any, withIcon = false) => tip(str, 'warn', withIcon),
    success: (str:any, withIcon = false) => tip(str, 'success', withIcon),
    error: (str:any, withIcon = false) => tip(str, 'error', withIcon)
}